package com.gewu.pm.ui.activity.clockin;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import com.gewu.pm.R;
import com.gewu.pm.app.AppActivity;
import com.gewu.pm.bean.AttendanceRecordBean;
import com.gewu.pm.other.IntentKey;
import com.hjq.bar.TitleBar;

/**
 * 打卡详情Activity
 */
public final class ClockInDetailActivity extends AppActivity {

    private static final String INTENT_KEY_BEAN = "bean";
    private static final String INTENT_KEY_ID = "id";

    private TitleBar mTitleBar;
    private TextView tvSignInTime;
    private TextView tvSignInLocation;
    private TextView tvSignOutTime;
    private TextView tvSignOutLocation;

    private AttendanceRecordBean mBean;
    private String mRecordId;

    public static void start(Context context, AttendanceRecordBean bean) {
        Intent intent = new Intent(context, ClockInDetailActivity.class);
        intent.putExtra(INTENT_KEY_BEAN, bean);
        context.startActivity(intent);
    }

    public static void start(Context context, String id) {
        Intent intent = new Intent(context, ClockInDetailActivity.class);
        intent.putExtra(IntentKey.ID, id);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.clock_in_detail_activity;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        mTitleBar = findViewById(R.id.tb_title);
        tvSignInTime = findViewById(R.id.tv_sign_in_time);
        tvSignInLocation = findViewById(R.id.tv_sign_in_location);
        tvSignOutTime = findViewById(R.id.tv_sign_out_time);
        tvSignOutLocation = findViewById(R.id.tv_sign_out_location);
    }

    @Override
    protected void initData() {
        // 获取传递的数据
        mBean = getIntent().getParcelableExtra(INTENT_KEY_BEAN);
        mRecordId = getIntent().getStringExtra(IntentKey.ID);
        
        if (mBean == null && mRecordId == null) {
            finish();
            return;
        }

        // 如果传递的是id，需要根据id加载数据
        if (mRecordId != null) {
            // TODO: 根据id从服务器加载详情数据
            toast("加载打卡记录详情，ID: " + mRecordId);
            return;
        }

        // 显示数据
        tvSignInTime.setText(mBean.getSignInTime() != null ? mBean.getSignInTime() : "未打卡");
        tvSignInLocation.setText(mBean.getSignInLocation() != null ? mBean.getSignInLocation() : "浙江省杭州市西湖区xxxxxxxxxxxxxx");
        tvSignOutTime.setText(mBean.getSignOutTime() != null ? mBean.getSignOutTime() : "未打卡");
        tvSignOutLocation.setText(mBean.getSignOutLocation() != null ? mBean.getSignOutLocation() : "浙江省杭州市西湖区xxxxxxxxxxxxxx");
    }
}
